package com.sz.sidi.oa.ui.enitor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.htmltext.HtmlComposer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.ui.forms.widgets.Form;

import util.DataSource;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableViewerColumn;

import com.sz.sidi.oa.katable.DoctorConfiguration;
import com.sz.sidi.oa.katable.ShowKTable;

import de.kupzog.ktable.SWTX;

public class AlarmEditor extends EditorPart {

	public static final String ID = "enitor.AlarmEditor"; //$NON-NLS-1$
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	private Text text;
	private Text text_1;
	public ShowKTable showKTable1;
	public final static int L = SWTX.ALIGN_HORIZONTAL_LEFT;
	private Table table;
	private Combo combo,combo_1,combo_2;
	private Button btnNewButton;
	private HtmlComposer composer;
	private ToolItem tltmA_1,item1,item2,item;
	public AlarmEditor() {
		setTitleImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/page_16.png"));
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		parent.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(composite, SWT.BOTTOM);
		tabFolder.setSelection(1);
		tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		
		TabItem tbtmNewItem = new TabItem(tabFolder, SWT.NONE);
		tbtmNewItem.setToolTipText("首页信息设置");
		tbtmNewItem.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		tbtmNewItem.setText("首页信息设置");
		tbtmNewItem.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		
		SashForm sashForm = new SashForm(tabFolder, SWT.BORDER | SWT.SMOOTH);
		sashForm.setSashWidth(1);
		tbtmNewItem.setControl(sashForm);
		formToolkit.paintBordersFor(sashForm);
		Composite composite_2 = new Composite(sashForm, SWT.NONE);
		formToolkit.adapt(composite_2);
		formToolkit.paintBordersFor(composite_2);
		composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		showKTable1 = new ShowKTable(composite_2, SWT.H_SCROLL | SWT.V_SCROLL);
		showKTable1.setColorTopBorder(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
		showKTable1.setColorRightBorder(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
		showKTable1.setColorLeftBorder(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
		showKTable1.setToolTipText("通知/公告");
		showKTable1.setTitlesAndProperties(new String[] { "序号","内容"},
				new String[] { "fcode", "fmc" });
		showKTable1.setColumnAligns(new int[] { L,L});
		showKTable1.setColumnWidths(new int[] { 30, 150});
		showKTable1.setBackground(Display.getCurrent().getSystemColor(
				SWT.COLOR_LIST_BACKGROUND));
		showKTable1.setVisible(true);
		formToolkit.adapt(showKTable1);
		formToolkit.paintBordersFor(showKTable1);
		
		
		
		Composite composite_7 = new Composite(sashForm, SWT.NONE);
		formToolkit.adapt(composite_7);
		formToolkit.paintBordersFor(composite_7);
		sashForm.setWeights(new int[] {2, 8});
		
		composite_7.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_7.setLayout(new GridLayout(1, false));
		
		Section sctnNewSection = formToolkit.createSection(composite_7, Section.FOCUS_TITLE | Section.TWISTIE | Section.TITLE_BAR);
		sctnNewSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		formToolkit.paintBordersFor(sctnNewSection);
		sctnNewSection.setText("通知/公告主题");
		Composite sectionPanel = formToolkit.createComposite(sctnNewSection);  
		FillLayout fl_sectionPanel = new FillLayout();
		sectionPanel.setLayout(fl_sectionPanel); 
		sctnNewSection.setClient(sectionPanel);
		formToolkit.createCompositeSeparator(sctnNewSection);
		sctnNewSection.setClient(sectionPanel );
		sctnNewSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		ToolBar bar = new ToolBar(sctnNewSection, SWT.FLAT | SWT.RIGHT);  
		sctnNewSection.setTextClient(bar);  
		tltmA_1 = new ToolItem(bar, SWT.NONE);
		tltmA_1.setText("新建");
		tltmA_1.setToolTipText("新建");
		tltmA_1.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/drop-add.gif"));
		tltmA_1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				doPost(DataSource.doadd);
			}
		});
		
		item= new ToolItem(bar, SWT.NONE);
		item.setText("保存");
		item.setToolTipText("保存");
		item.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/save_32.png"));
		item.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				doPost(DataSource.dosave);
			}
		});
		item1= new ToolItem(bar, SWT.NONE);
		item1.setText("删除");
		item1.setToolTipText("删除");
		item1.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/close_32.png"));
		item1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				doPost(DataSource.dodelete);
			}
		});
		item2= new ToolItem(bar, SWT.NONE);
		item2.setText("刷新");
		item2.setToolTipText("刷新");
		item2.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/loading.gif"));
		item2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				doPost(DataSource.dofresh);
			}
		});
		Group group = new Group(composite_7, SWT.SHADOW_ETCHED_IN);
		group.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		group.setText("基本信息");
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		formToolkit.adapt(group);
		formToolkit.paintBordersFor(group);
		group.setLayout(new GridLayout(3, false));
		
		Label label = new Label(group, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		formToolkit.adapt(label, true, true);
		label.setText("通知/公告标题：");
		
		text = new Text(group, SWT.BORDER);
		GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_text.widthHint = 350;
		text.setLayoutData(gd_text);
		formToolkit.adapt(text, true, true);
		
		Label lblNewLabel_2 = new Label(group, SWT.NONE);
		lblNewLabel_2.setToolTipText("带有*号为必填项");
		formToolkit.adapt(lblNewLabel_2, true, true);
		lblNewLabel_2.setText("*");
		
		Label lblNewLabel = new Label(group, SWT.NONE);
		formToolkit.adapt(lblNewLabel, true, true);
		lblNewLabel.setText("重要级别：");
		
		combo = new Combo(group, SWT.READ_ONLY);
		combo.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
		combo.setItems(new String[] {"一般", "中等", "重要"});
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		formToolkit.adapt(combo);
		formToolkit.paintBordersFor(combo);
		combo.select(0);
		
		Label lblNewLabel_3 = new Label(group, SWT.NONE);
		lblNewLabel_3.setToolTipText("带有*号为必填项");
		formToolkit.adapt(lblNewLabel_3, true, true);
		lblNewLabel_3.setText("*");
		
		Label label_1 = new Label(group, SWT.NONE);
		formToolkit.adapt(label_1, true, true);
		label_1.setText("可查阅部门：");
		
		combo_1 = new Combo(group, SWT.READ_ONLY);
		combo_1.setItems(new String[] {"全部"});
		combo_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		formToolkit.adapt(combo_1);
		formToolkit.paintBordersFor(combo_1);
		combo_1.select(0);
		new Label(group, SWT.NONE);
		
		Label label_2 = new Label(group, SWT.NONE);
		formToolkit.adapt(label_2, true, true);
		label_2.setText("首页显示类型：");
		
		combo_2 = new Combo(group, SWT.READ_ONLY);
		combo_2.setItems(new String[] {"通知公告", "公司新闻", "人事公告"});
		combo_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		formToolkit.adapt(combo_2);
		formToolkit.paintBordersFor(combo_2);
		combo_2.select(0);
		
		Label lblNewLabel_4 = new Label(group, SWT.NONE);
		lblNewLabel_4.setToolTipText("带有*号为必填项");
		formToolkit.adapt(lblNewLabel_4, true, true);
		lblNewLabel_4.setText("*");
		
		Label lblNewLabel_1 = new Label(group, SWT.NONE);
		formToolkit.adapt(lblNewLabel_1, true, true);
		lblNewLabel_1.setText("附件上传：");
		
		text_1 = new Text(group, SWT.BORDER | SWT.READ_ONLY);
		text_1.setEnabled(false);
		text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		formToolkit.adapt(text_1, true, true);
		
		btnNewButton = new Button(group, SWT.NONE);
		btnNewButton.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/add_16.png"));
		formToolkit.adapt(btnNewButton, true, true);
		btnNewButton.setText("上传");
		
		Section sctnNewSection_1 = formToolkit.createSection(composite_7, Section.TWISTIE | Section.TITLE_BAR);
		sctnNewSection_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		formToolkit.paintBordersFor(sctnNewSection_1);
		sctnNewSection_1.setText("通知/公告内容");
		
		Composite composite_6 = formToolkit.createComposite(composite_7, SWT.BORDER);
		composite_6.setLayout(new GridLayout(1, false));
		composite_6.setLayoutData(new GridData(GridData.FILL_BOTH));
		composer = new HtmlComposer(composite_6, SWT.NONE, DataSource.url);
		composer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		formToolkit.paintBordersFor(composite_6);
		
		TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
		tabItem_1.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		tabItem_1.setText("人事公告");
		tabItem_1.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		
		Composite composite_3 = new Composite(tabFolder, SWT.NONE);
		tabItem_1.setControl(composite_3);
		
		TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
		tabItem_2.setText("客户统计");
		tabItem_2.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		
		Composite composite_4 = new Composite(tabFolder, SWT.NONE);
		tabItem_2.setControl(composite_4);
		
		TabItem tbtmNewItem_1 = new TabItem(tabFolder, SWT.NONE);
		tbtmNewItem_1.setText("工作日记看板");
		tbtmNewItem_1.setImage(ResourceManager.getPluginImage("com.sz.sidi.oa", "icons/image/calendar.gif"));
		
		Composite composite_5 = new Composite(tabFolder, SWT.NONE);
		tbtmNewItem_1.setControl(composite_5);

		initDate();
	}

	private void initDate() {
		Control[] enterList = {text,combo,combo_1,combo_2};
		DoctorConfiguration.setEnterList(enterList);
	}

	public void doPost(Integer type) {
		if (type == DataSource.doadd) {
			composer.setHtml("");
			text.setText("");
			text_1.setText("");
			combo.select(0);
			text.setFocus();
			return;
		}
		if (type == DataSource.dosave) {
			composer.refresh();
			return;
		}
		if (type == DataSource.dodelete) {
			composer.refresh();
			return;
		}
		if (type == DataSource.dofresh) {
			
			return;
		}
	}
	
	@Override
	public void setFocus() {
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		monitor.beginTask("正在保存，请稍候......",
				IProgressMonitor.UNKNOWN);
	}

	@Override
	public void doSaveAs() {
		// Do the Save As operation
	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		 this.setInput(new EditorInput(ID));
	     this.setSite(site);
	}

	@Override
	public boolean isDirty() {
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		return false;
	}
}
